//
//  CZstatusLodeViewModel.swift
//  weibo24
//
//  Created by 李文峰 on 16/3/4.
//  Copyright © 2016年 fengten. All rights reserved.
//

import UIKit
import AFNetworking
class CZstatusLodeViewModel: NSObject {
    
    //定义一数组接受数据
    lazy var array: [CZStatusViewModel] = [CZStatusViewModel]()
    
    //请求网络数据
    
    func loadData(finish: ()->()){
        
        let afn = AFHTTPSessionManager()
        
        let parame = [
            "access_token": CZUserViewModel.shareInstance.acceaa_token ?? ""
        ]
        afn.GET("https://api.weibo.com/2/statuses/home_timeline.json", parameters: parame, progress: nil, success: { (_ , JSON) -> Void in
            
//            print(JSON)
            
            if let json = JSON as? [String : NSObject]{
                
                if let statuses = json["statuses"] as? [[String: NSObject]]{
                    
                    for statue in statuses {
//                      print(statue)
                        let statusModel = CZStatusModel(dict: statue)
                        
                        //添加到数组里
                        // 我们把 Model赋值放置在 ViewModel里
                        let viewModel = CZStatusViewModel()
                        viewModel.statuesModel = statusModel
                        
                       print(viewModel)
                        self.array.append(viewModel)

                    
                    finish()
                        
                    }
                    
                    
                }
                
            }
            
            
            }) { (_ , error) -> Void in
                
                print(error)
        }
        
    }

}
